/***************************************************************************
 *   Copyright (C) 2009 by Zheng Yonglei
 *   zhengyonglei@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "TestEndDialog.h"
#include "Logger.h"

TestEndDialog::TestEndDialog(QDialog *parent)
    : QDialog(parent),
    mSelectedTask(ST_None)
{
	ui.setupUi(this);

	QString text = QString(tr("This test is finished."));
	text.append(QString("\n"));
	text.append(QString(tr("Do you want to continue this test?")));
	text.append(QString("\n"));
	text.append(QString(tr("Or start a new one?")));
	ui.textLabel->setText(text);
	ui.textLabel->setAlignment(Qt::AlignHCenter | Qt::AlignJustify);
	QFont font;
	font.setPointSize(16);
	ui.textLabel->setFont(font);
	this->setWindowTitle(QString(tr("End of test")));
	this->setWindowFlags(Qt::WindowStaysOnTopHint);
	ui.cancelButton->setIcon(QIcon(":/pixmaps/cancel-256.png"));
	ui.analyseDataButton->setIcon(QIcon(":/pixmaps/kchart.png"));
	ui.selectListButton->setIcon(QIcon(":/pixmaps/fileopen-256.png"));
	ui.endTestButton->setIcon(QIcon(":/pixmaps/player_stop-256.png"));

	QObject::connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
	QObject::connect(ui.endTestButton, SIGNAL(clicked()), this, SLOT(endTestButtonClicked()));
	QObject::connect(ui.selectListButton, SIGNAL(clicked()), this, SLOT(selectListButtonClicked()));
	QObject::connect(ui.analyseDataButton, SIGNAL(clicked()), this, SLOT(analyseDataButtonClicked()));
}

TestEndDialog::~TestEndDialog()
{

}

void TestEndDialog::paintEvent ( QPaintEvent * event )
{
	QImage pixmap(QString(":/pixmaps/dialog-information.png"));
	QRect target = QRect(0, 0, ui.iconWidget->geometry().width(), ui.iconWidget->geometry().height());
	pixmap = pixmap.scaled(QSize(target.width(), target.height()), Qt::KeepAspectRatio);
	int tcx = target.x() + target.width()/2;
	int tcy = target.y() + target.height()/2;
	QPainter painter(this);
	painter.drawImage(tcx - pixmap.width()/2, tcy - pixmap.height()/2, pixmap);
}

void TestEndDialog::cancelButtonClicked()
{
	mSelectedTask = ST_None;
	this->done(int(mSelectedTask));
}

void TestEndDialog::endTestButtonClicked()
{
	mSelectedTask = ST_End;
	this->done(int(mSelectedTask));
}

void TestEndDialog::selectListButtonClicked()
{
	mSelectedTask = ST_OpenList;
	this->done(int(mSelectedTask));
}

void TestEndDialog::analyseDataButtonClicked()
{
	mSelectedTask = ST_Analyse;
	this->done(int(mSelectedTask));
}
